package co.yixiang.hw.repository;

import co.yixiang.hw.domain.YxUserAddress;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @author Walert
* @date 2020-02-18
*/
public interface YxUserAddressRepository extends JpaRepository<YxUserAddress, Integer>, JpaSpecificationExecutor<YxUserAddress> {

    /**
     * 根据用户ID设置用户收货地址位非默认状态
     * @param uid
     */
    @Modifying
    @Query(value = "update yx_user_address set is_default = 0 where uid = ?1 and is_default = 1",nativeQuery = true)
    void updateDefaultStatus(Integer uid);

    List<YxUserAddress> findAllByUidAndIsDelOrderByIsDefaultDesc(Integer uid, Integer isDel);

}